package cn.zmall.manager.service.impl;

import cn.zmall.common.exception.ZmallException;
import cn.zmall.manager.mapper.TbExpressMapper;
import cn.zmall.manager.pojo.TbExpress;
import cn.zmall.manager.pojo.TbExpressExample;
import cn.zmall.manager.service.ExpressService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

/**
 * @Author cxy
 * @Date 2020/11/13 15:37
 * @Version 1.0
 */
public class ExpressServiceImpl implements ExpressService {

    @Autowired
    private TbExpressMapper tbExpressMapper;


    @Override
    public List<TbExpress> getListExpress() {
        TbExpressExample example = new TbExpressExample();
        example.setOrderByClause("sort_order asc");
        return tbExpressMapper.selectByExample(example);
    }

    @Override
    public int addExpress(TbExpress tbExpress) {
        if (tbExpressMapper.insert(tbExpress) != 1){
            return -1;
        }
        return 1;
    }

    @Override
    public int delExpress(Integer expressId) {
        if (tbExpressMapper.deleteByPrimaryKey(expressId) != 1){
            return -1;
        }
        return 1;
    }

    @Override
    public int updateExpress(TbExpress tbExpress) {
        tbExpress.setUpdated(new Date());
        if(tbExpressMapper.updateByPrimaryKey(tbExpress) != 1){
            return -1;
        }
        return 1;
    }
}
